/*
 * @Author: moeWang
 * @Date: 2021-09-08 15:08:39
 * @LastEditTime: 2021-09-08 15:18:38
 * @LastEditors: moeWang
 * @Description: 工厂模式
 * @FilePath: \front-end-design-mode\code\Factory.JS
 */

/* 
    工厂模式定义创建对象的接口，但由子类决定实例化谁
*/

function Employee(type) {
    var employee
    if (type === 'be') {
        employee = new BackEndDeveloper()
    } else if (type === 'fe') {
        employee = new FrontEndDeveloper()
    }
    employee.introduction = function () {
        console.log('I am a ' + this.position + ', and ' + this.tool);
    }
    return employee
}

function BackEndDeveloper() {
    this.position = 'Back end engineer'
    this.tool = 'I use idea'
}

function FrontEndDeveloper() {
    this.position = 'Front end engineer'
    this.tool = 'I use VS Code'
}

var moe = Employee('fe')
moe.introduction()

var jack = Employee('be')
jack.introduction()